using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using MEA.AE_Data.Config;

namespace MEA.AE_Data
{
	public class Var
	{
		private float min;

		private float max;

		private float wert;

		private string name;

		private ConfigBase.EStringFormat format;

		public string Ecu_message;

		public ConfigLiveView.ESignals Ecu_Emessage;

		private ConfigLiveViewBase.ELiveViewSigClass sigClass;

		private Color lineColor;

		public ArrayList timestamps;

		public List<PointF> data;

		public Hashtable SessionMarker;

		public Hashtable SessionMarkerComment;

		public float yscal;

		private double lastXval;

		public ConfigBase.EStringFormat Format
		{
			get
			{
				return format;
			}
		}

		public string Name
		{
			get
			{
				return name;
			}
			set
			{
				name = value;
			}
		}

		public ConfigLiveViewBase.ELiveViewSigClass SigClass
		{
			get
			{
				return sigClass;
			}
			set
			{
				sigClass = value;
			}
		}

		public string Titel
		{
			get
			{
				return name;
			}
			set
			{
				name = value;
			}
		}

		public float Min
		{
			get
			{
				return min;
			}
			set
			{
				min = value;
			}
		}

		public float Max
		{
			get
			{
				return max;
			}
			set
			{
				max = value;
			}
		}

		public Color LineColor
		{
			get
			{
				return lineColor;
			}
			set
			{
				lineColor = value;
			}
		}

		public float Wert
		{
			get
			{
				return wert;
			}
			set
			{
				wert = value;
			}
		}

		public Var(float min, float max, string name, ConfigLiveViewBase.ELiveViewSigClass sigclass, ConfigBase.EStringFormat format)
		{
			this.min = min;
			this.max = max;
			wert = float.NaN;
			this.name = name;
			sigClass = sigclass;
			this.format = format;
			data = new List<PointF>();
			SessionMarker = new Hashtable();
			timestamps = new ArrayList();
			SessionMarkerComment = new Hashtable();
			if (this.max - this.min > 0f)
			{
				yscal = (this.max - this.min) / 10f;
			}
			else
			{
				yscal = 1f;
			}
		}

		public Var(float min, float max, string name, ConfigLiveViewBase.ELiveViewSigClass sigclass, ConfigBase.EStringFormat format, Color sigcol)
		{
			this.min = min;
			this.max = max;
			wert = float.NaN;
			this.name = name;
			sigClass = sigclass;
			this.format = format;
			lineColor = sigcol;
			data = new List<PointF>();
			SessionMarker = new Hashtable();
			timestamps = new ArrayList();
			SessionMarkerComment = new Hashtable();
			if (this.max - this.min > 0f)
			{
				yscal = (this.max - this.min) / 10f;
			}
			else
			{
				yscal = 1f;
			}
		}

		public Var(ref LogSignalDatalog logSig, string name)
		{
			min = logSig.Ymin;
			max = logSig.Ymax;
			wert = float.NaN;
			this.name = name;
			sigClass = logSig.sigClass;
			format = logSig.format;
			lineColor = logSig.color;
			data = new List<PointF>();
			SessionMarker = new Hashtable();
			timestamps = new ArrayList();
			SessionMarkerComment = new Hashtable();
			if (max - min > 0f)
			{
				yscal = (max - min) / 10f;
			}
			else
			{
				yscal = 1f;
			}
		}

		public Var(ref LogSignalLiveView logSig, string name)
		{
			min = logSig.Ymin;
			max = logSig.Ymax;
			wert = float.NaN;
			this.name = name;
			sigClass = logSig.sigClass;
			format = logSig.format;
			lineColor = logSig.color;
			Ecu_message = logSig.ECU_Message;
			Ecu_Emessage = logSig.ECU_EMesage;
			data = new List<PointF>();
			SessionMarker = new Hashtable();
			timestamps = new ArrayList();
			SessionMarkerComment = new Hashtable();
			if (max - min > 0f)
			{
				yscal = (max - min) / 10f;
			}
			else
			{
				yscal = 1f;
			}
			lastXval = 0.0;
		}

		public void Addpoint(DateTime recordStart, int interval_ms, float v)
		{
			PointF pointF = new PointF((float)lastXval, v);
			lock (timestamps)
			{
				DateTime dateTime = recordStart.AddMilliseconds(timestamps.Count * interval_ms);
				timestamps.Add(dateTime);
			}
			lock (data)
			{
				if (data.Count > 0)
				{
					lastXval = data[data.Count - 1].X;
				}
				else
				{
					lastXval = 0.0;
				}
				lastXval += (double)interval_ms / 1000.0;
				pointF = new PointF((float)lastXval, v);
				data.Add(pointF);
			}
		}

		public void Addpoint(DateTime timeSt, float xOffset, float v, bool sessionmarker, bool newsessionSpace)
		{
			timestamps.Add(timeSt);
			float num;
			if (data.Count == 0)
			{
				num = xOffset;
			}
			else
			{
				PointF pointF = data[data.Count - 1];
				num = ((!(xOffset > 0f)) ? pointF.X : xOffset);
				if (newsessionSpace)
				{
					num -= 10f;
				}
			}
			PointF pointF2 = new PointF(num - 1f, v);
			if (sessionmarker)
			{
				lock (SessionMarker.SyncRoot)
				{
					lock (SessionMarkerComment.SyncRoot)
					{
						if (!SessionMarker.Contains(pointF2))
						{
							SessionMarker.Add(pointF2, timeSt);
							SessionMarkerComment.Add(pointF2, "LeadIn");
						}
					}
				}
			}
			data.Add(pointF2);
		}

		public void Addpoint(DateTime time, int delta, float xOffset, int interval_ms, float v, bool sessionmarker, bool newsessionSpace)
		{
			DateTime dateTime = time.AddMilliseconds(delta * interval_ms);
			timestamps.Add(dateTime);
			float num;
			if (data.Count == 0)
			{
				num = xOffset;
			}
			else
			{
				PointF pointF = data[data.Count - 1];
				num = ((!(xOffset > 0f)) ? pointF.X : xOffset);
				if (newsessionSpace)
				{
					num -= 10f;
				}
			}
			PointF pointF2 = new PointF(num - (float)interval_ms / 1000f, v);
			if (sessionmarker)
			{
				lock (SessionMarker.SyncRoot)
				{
					lock (SessionMarkerComment.SyncRoot)
					{
						if (!SessionMarker.Contains(pointF2))
						{
							SessionMarker.Add(pointF2, dateTime);
							SessionMarkerComment.Add(pointF2, "LeadIn");
						}
					}
				}
			}
			data.Add(pointF2);
		}

		public void addLeadOutSessionMarker(int elemCount, bool LoError)
		{
			int num = data.Count - elemCount;
			bool flag = false;
			PointF pointF;
			string value;
			if (elemCount != 0)
			{
				pointF = data[num];
				lock (SessionMarker.SyncRoot)
				{
					if (!SessionMarker.Contains(pointF))
					{
						SessionMarker.Add(pointF, timestamps[num]);
						flag = true;
					}
				}
				if (!flag)
				{
					return;
				}
				value = ((!LoError) ? "LeadIn-Out" : "LeadIn-Out**");
				lock (SessionMarkerComment.SyncRoot)
				{
					if (!SessionMarkerComment.Contains(data[num]))
					{
						SessionMarkerComment.Add(data[num], value);
					}
					return;
				}
			}
			pointF = data[num - 1];
			pointF.X -= 10f;
			data.Add(pointF);
			value = "LeadIn-Out*";
			lock (SessionMarkerComment.SyncRoot)
			{
				SessionMarkerComment.Add(data[num], value);
			}
		}
	}
}
